#include "DialogTraining.h"
#include <QTimer>
#include <QDebug>

DialogTraining::DialogTraining(QWidget *parent) : QDialog(parent), ui(new Ui::DialogTraining) {
	ui->setupUi(this);
	timer = new QTimer;
	timer->setSingleShot(1);
	connect(timer, SIGNAL(timeout()), this, SLOT(showWord()));
	connect(ui->buttonStop, SIGNAL(clicked()), this, SLOT(reject()));
	connect(ui->buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
	connect(ui->buttonNext, SIGNAL(clicked()), this, SLOT(nextStep()));
}

void DialogTraining::nextStep() {
	if(ui->lineEditAnswer->text() != currentWord->translate()) {
		ui->labelTranslate->setText("<font color=\"red\">" + currentWord->translate() + "</font>");
		currentWord->minus();
	} else {
		ui->labelTranslate->setText("<font color=\"green\">" + currentWord->translate() + "</font>");
		currentWord->plus();
	}
	currentStep++;
	timer->start(1000);
}
void DialogTraining::showWord() {
	if(currentStep > allSteps) {
		ui->buttonNext->hide();
		ui->buttonStop->hide();
		ui->buttonOk->show();
		return;
	}
	currentWord =  p_list->at(currentStep - 1);
	ui->labelStep->setText(num(currentStep) + "/" + num(allSteps));
	ui->labelWord->setText(currentWord->word());
	ui->lineEditAnswer->setText("");
	ui->labelTranslate->setText("");
}
DialogTraining::~DialogTraining() { delete ui; }
